package com.kucai.yifaqapp.presenter.fragment;

import android.widget.Toast;

import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.ResGameDetails;
import com.kucai.yifaqapp.model.network.entity.res.ResMoney;
import com.kucai.yifaqapp.model.network.entity.res.ResSetbet;
import com.kucai.yifaqapp.model.network.entity.res.Resanhuikuaisan;
import com.kucai.yifaqapp.model.network.entity.res.Resgansuk3;
import com.kucai.yifaqapp.model.network.entity.res.Resguangxik3;
import com.kucai.yifaqapp.model.network.entity.res.Resguizhouk3;
import com.kucai.yifaqapp.model.network.entity.res.Reshebeik3;
import com.kucai.yifaqapp.model.network.entity.res.Reshubeik3;
import com.kucai.yifaqapp.model.network.entity.res.Resjiangsuk3;
import com.kucai.yifaqapp.model.network.entity.res.Resmiaosukuaisan;
import com.kucai.yifaqapp.ui.fragment.gameFragment.KSFragment;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/10.
 */

public class KSFragmentPresenter extends BaseFragmentPresenter<KSFragment> {


    public KSFragmentPresenter(KSFragment mFragment) {
        super(mFragment);
    }

    //获取游戏详情
    public void getgamesdetail(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do", gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if (("秒速快3").equals(resGameDetails.data.game_name) || ("江苏快3").equals(resGameDetails.data.game_name) ||
                                    ("广西快3").equals(resGameDetails.data.game_name) || ("湖北快3").equals(resGameDetails.data.game_name) ||
                                    ("甘肃快3").equals(resGameDetails.data.game_name) || ("河北快3").equals(resGameDetails.data.game_name) ||
                                    ("贵州快3").equals(resGameDetails.data.game_name) || ("安徽快3").equals(resGameDetails.data.game_name)) {
                                mFragment.miaosukuaisan(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    } //获取游戏详情

    public void getgamesdetail1(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do", gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if (("秒速快3").equals(resGameDetails.data.game_name) || ("江苏快3").equals(resGameDetails.data.game_name) ||
                                    ("广西快3").equals(resGameDetails.data.game_name) || ("湖北快3").equals(resGameDetails.data.game_name) ||
                                    ("甘肃快3").equals(resGameDetails.data.game_name) || ("河北快3").equals(resGameDetails.data.game_name) ||
                                    ("贵州快3").equals(resGameDetails.data.game_name) || ("安徽快3").equals(resGameDetails.data.game_name)) {
                                mFragment.miaosukuaisan1(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //下注
    public void Betbet(final String data, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .Betbet(HttpAdress.getuseAdress() + "api/m/lottery/bet.do", data, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResSetbet>(mFragment) {
                    @Override
                    protected void onCustomNext(ResSetbet resOods) {

                        if ("200".equals(resOods.code)) {
                            mFragment.betsuccses();
                        } else {
                            Toast.makeText(mFragment.getContext(), resOods.msg, Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取余额
    public void getmoney(String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getmoney(HttpAdress.getuseAdress() + "api/m/user/getMoney", token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResMoney>() {
                    @Override
                    protected void onCustomNext(ResMoney resOods) {
                        if (resOods.code == 0) {
                            mFragment.moneychange(resOods);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //秒速快三
    public void getmiaosukuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getmiaosukuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resmiaosukuaisan>() {
                    @Override
                    protected void onCustomNext(Resmiaosukuaisan resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatamiaosukuaisan(resOods.data);
                        } else if (resOods.code.equals("60011")) {
                            mFragment.restartlogin();
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //安徽快三
    public void getanhuikuaisanoddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getanhuikuaisanoddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resanhuikuaisan>() {
                    @Override
                    protected void onCustomNext(Resanhuikuaisan resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdataanhuikuaisan(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //江苏快三
    public void getjiangsukuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getjiangsukuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resjiangsuk3>() {
                    @Override
                    protected void onCustomNext(Resjiangsuk3 resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdajiangsukuaisan(resOods.data);
                        }else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //湖北快三
    public void gethubeikuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .gethubeikuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Reshubeik3>() {
                    @Override
                    protected void onCustomNext(Reshubeik3 resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdahubeikuaisan(resOods.data);
                        }  else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //广西快三
    public void getguangxikuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getguangxikuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resguangxik3>() {
                    @Override
                    protected void onCustomNext(Resguangxik3 resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setguangxikuaisan(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //甘肃快三
    public void getgansukuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getgansukuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resgansuk3>() {
                    @Override
                    protected void onCustomNext(Resgansuk3 resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setgansukuaisan(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //河北快三
    public void gethebeikuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .gethebeikuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Reshebeik3>() {
                    @Override
                    protected void onCustomNext(Reshebeik3 resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.sethebeikuaisan(resOods.data);
                        }  else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //贵州快三
    public void getguizhoukuaisanddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getguizhoukuaisanddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resguizhouk3>() {
                    @Override
                    protected void onCustomNext(Resguizhouk3 resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setguizhoukuaisan(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

}

